package com.object.oriented.exam.system5.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.object.oriented.exam.system5.entity.Answer;
import com.object.oriented.exam.system5.entity.AnswerVo;
import com.object.oriented.exam.system5.service.AnswerService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xdf
 * @date 2023-06-14
 */
@RestController
@RequestMapping("/answer")
public class AnswerController {

    @Resource
    AnswerService answerService;

    /**
     * 给（主观）题目评分
     * @param answer
     * @return
     */
    @PostMapping("/mark")
    public Boolean markAnswer(@RequestBody Answer answer){
        return answerService.markAnswer(answer);
    }

    /**
     * 提交答案
     * @param answer
     * @return
     */
    @PostMapping("/commit")
    public Boolean commitAnswer(@RequestBody Answer answer){
        return answerService.commitAnswer(answer);
    }

    @GetMapping("/{examId}/{current}/{size}")
    public List<Long> getStudent(@PathVariable Long examId, @PathVariable Long current, @PathVariable Long size){
        return answerService.getStudent(examId,current,size);
    }

    /**
     * 获取某个学生某次考试的答题记录
     * @param studentId
     * @param examId
     * @param current
     * @param size
     * @return
     */
        @GetMapping("/{studentId}/{examId}/{current}/{size}")
    public Page<AnswerVo> getStudentAnswer(@PathVariable Long studentId, @PathVariable Long examId, @PathVariable Long current, @PathVariable Long size){
        return answerService.getAnswer(studentId,examId,current,size);
    }

    /**
     * 获取学生做题总数
     * @param studentId
     * @return
     */
    @GetMapping("/total/{studentId}")
    public Integer getStudentAnswer(@PathVariable Long studentId){
        return answerService.totalAnswer(studentId);
    }

    @GetMapping("/{studentId}/{current}/{size}")
    public Page<AnswerVo> getStudentAnswer(@PathVariable Long studentId, @PathVariable Long current, @PathVariable Long size){
        return answerService.getAnswer(studentId,current,size);
    }
}
